<template>
	<div >
		<el-card shadow="hover">
			<div class=" mb15">
				<el-form :model="tableData.param" ref="queryRef" :inline="true" label-width="100px">
					<el-row>
						<el-col :span="6" >
							<el-form-item label="注册时间">
								<el-date-picker v-model="tableData.dateRange" type="datetimerange" size="default"
									style="width: 300px" range-separator="-" start-placeholder="开始日期"
									end-placeholder="结束日期"></el-date-picker>
							</el-form-item>
						</el-col>
						<el-col :span="6" >
							<el-form-item label="联系方式" prop="registerPhone">
								<el-input v-model="tableData.param.registerPhone" placeholder="请输入联系方式" clearable
									@keyup.enter.native="getList" />
							</el-form-item>
						</el-col>
						<el-col :span="6" >
							<el-form-item label="企业名称" prop="companyName">
								<el-input v-model="tableData.param.companyName" placeholder="请输入企业名称" clearable
									@keyup.enter.native="getList" />
							</el-form-item>
						</el-col>
						
						<el-col :span="6">
							<el-form-item>
								<el-button type="primary" @click="getList"><el-icon>
										<Search />
									</el-icon>搜索</el-button>
								<el-button @click="resetQuery(queryRef)"><el-icon>
										<Refresh />
									</el-icon>重置</el-button>
								<el-button type="primary" @click="exportFile" v-if="permissionStore.isPermissionsBtn('005001001')">
									<el-icon><Download /></el-icon>
									导出</el-button>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</div>
			<el-table v-loading="loading" :data="tableData.data">
				<el-table-column label="企业名称" align="center" prop="companyName" min-width="150px" />
				<el-table-column label="社会统一信用代码" align="center" prop="creditCode" min-width="150px" />
				<el-table-column label="法人" align="center" prop="legalName" min-width="100px" />
				<el-table-column label="经办人" align="center" prop="handName" min-width="100px" />
				<el-table-column label="联系方式" align="center" prop="handPhone" min-width="100px" />
				<el-table-column label="认证时间" align="center" prop="createTimeTxt" min-width="150px" />
				<el-table-column label="操作" align="center" class-name="small-padding" min-width="200px" fixed="right">
					<template #default="scope">
						<el-button type="primary" link @click="handleUpdate(scope.row)"><el-icon>
								<View />
							</el-icon>详情</el-button>
					</template>
				</el-table-column>
			</el-table>
			<pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNumber"
				v-model:limit="tableData.param.pageLength" @pagination="getList" />
		</el-card>
		<detailView ref="detailRef" @getList="getList"></detailView>
	</div>
</template>
<script lang="ts">
import { companyListApi } from '@/api/auditTask/enterpriseAuthentication';
import { toRefs, reactive, onMounted, ref, defineComponent, computed, getCurrentInstance, toRaw } from 'vue';
import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
import { formatDateTime, dateToTimestamp } from '@/utils/index'
import { usePermissionStore } from "@/store/modules/permission"
import dictionary from '@/utils/dictionary.json';
import detailView from './component/detail.vue';
import { getFile } from '@/utils/excel/excelUtil';
export default defineComponent({
	name: 'enterpriseAuthenticationList',//企业实名审核列表
	components: {
		detailView,
	},
	setup() {
		const { proxy } = <any>getCurrentInstance();
		const loading = ref(false);
		const queryRef = ref();
		const detailRef = ref();
		const permissionStore = usePermissionStore()
		const state = reactive({
			ids: [],
			tableData: {
				data: [],
				total: 0,
				loading: false,
				dateRange: [],
				param: {
					pageNumber: 1,
					pageLength: 10,
					registerPhone:'',
					companyName:'',
					registerBeginTime:null,
					registerEndTime:null
				},
			},
		});
		// 页面加载时
		onMounted(() => {
			initTableData();
			
		});
		// 初始化表格数据
		const initTableData = () => {
			getList();
		};
		/** 重置按钮操作 */
		const resetQuery = (formEl: FormInstance | undefined) => {
			if (!formEl) return;
			formEl.resetFields();
			state.tableData.dateRange = []
			getList();
		};
		// 获取列表数据
		const getList = () => {
			loading.value = true;
			if (state.tableData.dateRange.length > 0) {
				state.tableData.param.registerBeginTime = dateToTimestamp(state.tableData.dateRange[0])
				state.tableData.param.registerEndTime = dateToTimestamp(state.tableData.dateRange[1])
			} else {
				state.tableData.param.registerBeginTime = null
				state.tableData.param.registerEndTime = null
			}
			companyListApi(state.tableData.param).then((res: any) => {
				let list = res.data.list ?? [];
				state.tableData.data = list.map(item=>{
					item.createTimeTxt=formatDateTime(item.createTime)
					return item
				})
				console.log(state.tableData.data);
				state.tableData.total = res.data.total;
				loading.value = false;
			});
		};
		const handleUpdate = (row) => {
			detailRef.value.openDialog(row.companyCode);
		};
		// 导出文件
		const exportFile = async () => {
			getFile('/manager/company/export','企业认证')
		}

		return {
			proxy,
			loading,
			detailRef,
			queryRef,
			dictionary,
			permissionStore,
			resetQuery,
			getList,
			exportFile,
			formatDateTime,
			handleUpdate,
			...toRefs(state),
		};
	},
});
</script>
